import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'

const extMap = {
  cjs: 'cjs',
  es: 'js'
}
export default defineConfig({
  server: {
    port: 9091
  },
  build: {
    cssCodeSplit: true,
    emptyOutDir: true,

    lib: {
      name: 'index',
      entry: {
        index: './lib/main/index.ts',
        plugins: './lib/plugins/index.ts'
      },
      fileName: (format, entryName) => {
        console.log(format, entryName)
        return `${format}/${entryName}.${extMap[format]}`;
      }
    },
    rollupOptions: {
      output: [
        {
          format: 'cjs',
          exports: 'named',
          assetFileNames: 'styles/[name].[ext]'
        },
        {
          format: 'es',
          exports: 'named',
          assetFileNames: 'styles/[name].[ext]'
        },
      ]
    }
  },
  plugins: [
    dts({
      outputDir: './dist/types',
      tsConfigFilePath: './tsconfig.lib.json'
    })
  ]
})
